/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function(s) {
  let arrLeft = [];
  function isLeft(char) {
    switch(char) {
      case '(':
      case '{':
      case '[':
        return true;
      default:
        return false;
    }
  }
  function matching(left, right) {
    if(left === '(' && right === ')')
      return true;
    else if(left === '[' && right === ']')
      return true;
    else if(left === '{' && right === '}')
      return true;
    else
      return false;
  }
  for(let i = 0; i < s.length; i++) {
    if(isLeft(s[i])) {
      arrLeft.push(s[i]);
    } else {
      if(i == 0) {
        return false;
      } else {
        if(matching(arrLeft[arrLeft.length - 1], s[i])) {
          arrLeft.length = arrLeft.length - 1;
        } else {
          return false;
        }
      }
    }
  }
  return arrLeft.length === 0;
};
let s = "()";
console.log(isValid(s));
s = "()[]{}";
console.log(isValid(s));
s = "(]";
console.log(isValid(s));
s = "([)]";
console.log(isValid(s));
s = "{[]}";
console.log(isValid(s));
